{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 一、人脸识别"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.Azure"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1 `Face detect`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 面部检测\n",
    "import requests\n",
    "# json\n",
    "import json\n",
    "\n",
    "# set to your own subscription key value\n",
    "subscription_key = \"bc82061a471c42d985bdd4195cc73867\"\n",
    "assert subscription_key\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-jun.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文body\n",
    "image_url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603446871485&di=ea65241de93bde5ff5f6e0b12b3557f8&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F01%2F20191201160513_imlxt.thumb.400_0.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数parameters\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "\n",
    "# json.dumps 将json--->bytes\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# bytes or string   编码不同  *****  encoding =\"utf-8\"\n",
    "# response.text\n",
    "# response.content\n",
    "results = response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'cc1bb909-f18a-4dc5-b2fe-8cf151a3e2f6',\n",
       "  'faceRectangle': {'top': 97, 'left': 169, 'width': 107, 'height': 107},\n",
       "  'faceAttributes': {'smile': 0.998,\n",
       "   'headPose': {'pitch': 9.9, 'roll': -2.0, 'yaw': 18.9},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.998,\n",
       "    'neutral': 0.002,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.8},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.32},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.04,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.97},\n",
       "     {'color': 'brown', 'confidence': 0.97},\n",
       "     {'color': 'gray', 'confidence': 0.29},\n",
       "     {'color': 'other', 'confidence': 0.18},\n",
       "     {'color': 'blond', 'confidence': 0.09},\n",
       "     {'color': 'red', 'confidence': 0.07},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用Pandas简化数据\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.json_normalize(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceRectangle.top</th>\n",
       "      <th>faceRectangle.left</th>\n",
       "      <th>faceRectangle.width</th>\n",
       "      <th>faceRectangle.height</th>\n",
       "      <th>faceAttributes.smile</th>\n",
       "      <th>faceAttributes.headPose.pitch</th>\n",
       "      <th>faceAttributes.headPose.roll</th>\n",
       "      <th>faceAttributes.headPose.yaw</th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "      <th>...</th>\n",
       "      <th>faceAttributes.noise.value</th>\n",
       "      <th>faceAttributes.makeup.eyeMakeup</th>\n",
       "      <th>faceAttributes.makeup.lipMakeup</th>\n",
       "      <th>faceAttributes.accessories</th>\n",
       "      <th>faceAttributes.occlusion.foreheadOccluded</th>\n",
       "      <th>faceAttributes.occlusion.eyeOccluded</th>\n",
       "      <th>faceAttributes.occlusion.mouthOccluded</th>\n",
       "      <th>faceAttributes.hair.bald</th>\n",
       "      <th>faceAttributes.hair.invisible</th>\n",
       "      <th>faceAttributes.hair.hairColor</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>cc1bb909-f18a-4dc5-b2fe-8cf151a3e2f6</td>\n",
       "      <td>97</td>\n",
       "      <td>169</td>\n",
       "      <td>107</td>\n",
       "      <td>107</td>\n",
       "      <td>0.998</td>\n",
       "      <td>9.9</td>\n",
       "      <td>-2.0</td>\n",
       "      <td>18.9</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>0.32</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>[]</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0.04</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'black', 'confidence': 0.97}, {'col...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId  faceRectangle.top  \\\n",
       "0  cc1bb909-f18a-4dc5-b2fe-8cf151a3e2f6                 97   \n",
       "\n",
       "   faceRectangle.left  faceRectangle.width  faceRectangle.height  \\\n",
       "0                 169                  107                   107   \n",
       "\n",
       "   faceAttributes.smile  faceAttributes.headPose.pitch  \\\n",
       "0                 0.998                            9.9   \n",
       "\n",
       "   faceAttributes.headPose.roll  faceAttributes.headPose.yaw  \\\n",
       "0                          -2.0                         18.9   \n",
       "\n",
       "  faceAttributes.gender  ...  faceAttributes.noise.value  \\\n",
       "0                  male  ...                        0.32   \n",
       "\n",
       "   faceAttributes.makeup.eyeMakeup  faceAttributes.makeup.lipMakeup  \\\n",
       "0                             True                            False   \n",
       "\n",
       "   faceAttributes.accessories faceAttributes.occlusion.foreheadOccluded  \\\n",
       "0                          []                                     False   \n",
       "\n",
       "   faceAttributes.occlusion.eyeOccluded  \\\n",
       "0                                 False   \n",
       "\n",
       "   faceAttributes.occlusion.mouthOccluded  faceAttributes.hair.bald  \\\n",
       "0                                   False                      0.04   \n",
       "\n",
       "   faceAttributes.hair.invisible  \\\n",
       "0                          False   \n",
       "\n",
       "                       faceAttributes.hair.hairColor  \n",
       "0  [{'color': 'black', 'confidence': 0.97}, {'col...  \n",
       "\n",
       "[1 rows x 38 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2  `Face list & Face similar`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId = \"list_007\"\n",
    "create_facelists_url = \"https://api-jun.cognitiveservices.azure.com/face/v1.0/facelists/{}\"\n",
    "subscription_key = \"521405a0a018414bb5a331b10d3c311b\"\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "  \"name\": \"sample_list\",\n",
    "  \"userData\": \"相册\",\n",
    "  \"recognitionModel\": \"recognition_01\"\n",
    "    \n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId), headers=headers, json=data)\n",
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url = \"https://api-jun.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedfaces\"\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603451243506&di=223ac9c1f7572a05e54b2008ec02d9ab&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F01%2F20191201160513_imlxt.thumb.400_0.jpg\"\n",
    "\n",
    "params_add_face={\n",
    "    \"userData\":\"李振宁\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "r_add_face.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaceId': '1374fada-26f6-4ba6-bc94-a9e794a51de5'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.json() #返回persistedFaceId"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-jun.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedfaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code  #返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\",\"丘天惠\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\",\"林嘉茵\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\",\"汤玲萍\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\",\"曾雯燕\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\",\"谢依希\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/YuecongYang.png\",\"杨悦聪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg\",\"周雨\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg\",\"刘瑜鹏\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg\",\"陈嘉仪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/kg2000.jpg\",\"徐旖芊\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg\",\"刘心如\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuyu19.png\",\"刘宇\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/ltco.jpg\",\"李婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lucaszy.jpg\",\"黄智毅\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/pingzi0211.jpg\",\"黄慧文\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/shmimy-cn.jpg\",\"张铭睿\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/yichenting.jpg\",\"陈婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/coco022.jpg\",\"洪可凡\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lujizhi.png\",\"卢继志\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/zzlhyy.jpg\",\"张梓乐\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'bd0e47ff-58d4-4ab7-ad9d-370dab880497',\n",
       "  'faceRectangle': {'top': 97, 'left': 169, 'width': 107, 'height': 107},\n",
       "  'faceAttributes': {'smile': 0.998,\n",
       "   'headPose': {'pitch': 9.9, 'roll': -2.0, 'yaw': 18.9},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.998,\n",
       "    'neutral': 0.002,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.8},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.32},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.04,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.97},\n",
       "     {'color': 'brown', 'confidence': 0.97},\n",
       "     {'color': 'gray', 'confidence': 0.29},\n",
       "     {'color': 'other', 'confidence': 0.18},\n",
       "     {'color': 'blond', 'confidence': 0.09},\n",
       "     {'color': 'red', 'confidence': 0.07},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检测人脸\n",
    "face_api_url = 'https://api-jun.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "image_url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603451243506&di=223ac9c1f7572a05e54b2008ec02d9ab&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F01%2F20191201160513_imlxt.thumb.400_0.jpg'\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择模型\n",
    "    'recognitionModel':'recognition_01',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数，请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "response = requests.post(face_api_url, params=params,headers=headers, json={\"url\": image_url})\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '1374fada-26f6-4ba6-bc94-a9e794a51de5',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': 'c64170ef-ad93-408f-a226-647a0b05084e',\n",
       "  'confidence': 0.37464},\n",
       " {'persistedFaceId': '80f63719-e49b-4339-86c3-39174f722285',\n",
       "  'confidence': 0.3712},\n",
       " {'persistedFaceId': '0bf2587d-1859-4538-b213-a7b6834b3545',\n",
       "  'confidence': 0.36362},\n",
       " {'persistedFaceId': '1a63b72b-15be-421c-bddd-23e0aeada20a',\n",
       "  'confidence': 0.33239},\n",
       " {'persistedFaceId': 'b7a8d8c5-50a9-4b00-b8c2-935190d5fb16',\n",
       "  'confidence': 0.26854},\n",
       " {'persistedFaceId': 'c0faac8e-cb3f-48c7-81ce-e5e8f0121e08',\n",
       "  'confidence': 0.26598},\n",
       " {'persistedFaceId': '6ea2f3a0-f320-429b-a925-f20f51fbc1a2',\n",
       "  'confidence': 0.24914},\n",
       " {'persistedFaceId': 'aa22e7e8-6982-461c-bb1b-078d1a749788',\n",
       "  'confidence': 0.20007},\n",
       " {'persistedFaceId': '2dada7df-3292-4001-aeb6-4c8448be98eb',\n",
       "  'confidence': 0.16117}]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回人脸相似置信度\n",
    "findsimilars_url = \"https://api-jun.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "# 请求正文 faceID需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\"d49e1a4f-703e-4148-bf6f-def119d17417\", #取上方的faceID\n",
    "    \"faceListId\": \"list_007\",\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\" #matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)\n",
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '1374fada-26f6-4ba6-bc94-a9e794a51de5',\n",
       "   'userData': '李振宁'},\n",
       "  {'persistedFaceId': '9923a82f-54ae-4fa0-93ff-a8632e156110',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': 'c0faac8e-cb3f-48c7-81ce-e5e8f0121e08',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': 'b7a8d8c5-50a9-4b00-b8c2-935190d5fb16',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '1a63b72b-15be-421c-bddd-23e0aeada20a',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '2ccf8811-ec00-493f-9fb0-c6d18928a641',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': 'd78b42f7-1cbc-437e-ae90-71d5c827e56d',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '847f3691-2cc8-4c63-9673-815105277146',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': 'd81c998a-0bfc-4fd8-bd00-2c06e50902e7',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '2dada7df-3292-4001-aeb6-4c8448be98eb',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': 'c64170ef-ad93-408f-a226-647a0b05084e',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': '1512ca67-8e1d-4c95-877d-0e021cf12baf',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': 'd902078a-133b-489b-b89b-79ee0322debb',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': '0bf2587d-1859-4538-b213-a7b6834b3545',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '89f838e1-f31c-4139-a0f4-9143a80b435d',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '930bf6f4-0e19-498e-b762-201a52a4c8e7',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': '80f63719-e49b-4339-86c3-39174f722285',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': 'dadcbc6b-a994-424b-aa51-b33eda6f0ac8',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'aa22e7e8-6982-461c-bb1b-078d1a749788',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': '5d14f8be-2ef9-43b2-a6ad-de0ddb3a5314',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '6ea2f3a0-f320-429b-a925-f20f51fbc1a2',\n",
       "   'userData': '张梓乐'}],\n",
       " 'faceListId': 'list_007',\n",
       " 'name': 'sample_list',\n",
       " 'userData': '相册'}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看列表\n",
    "get_facelist_url = \"https://api-jun.cognitiveservices.azure.com/face/v1.0/facelists/{}\"\n",
    "r_get_facelist = requests.get(get_facelist_url.format(faceListId),headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374fada-26f6-4ba6-bc94-a9e794a51de5</td>\n",
       "      <td>李振宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9923a82f-54ae-4fa0-93ff-a8632e156110</td>\n",
       "      <td>丘天惠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>c0faac8e-cb3f-48c7-81ce-e5e8f0121e08</td>\n",
       "      <td>林嘉茵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b7a8d8c5-50a9-4b00-b8c2-935190d5fb16</td>\n",
       "      <td>汤玲萍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1a63b72b-15be-421c-bddd-23e0aeada20a</td>\n",
       "      <td>曾雯燕</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2ccf8811-ec00-493f-9fb0-c6d18928a641</td>\n",
       "      <td>谢依希</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>d78b42f7-1cbc-437e-ae90-71d5c827e56d</td>\n",
       "      <td>杨悦聪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>847f3691-2cc8-4c63-9673-815105277146</td>\n",
       "      <td>周雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>d81c998a-0bfc-4fd8-bd00-2c06e50902e7</td>\n",
       "      <td>刘瑜鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2dada7df-3292-4001-aeb6-4c8448be98eb</td>\n",
       "      <td>陈嘉仪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>c64170ef-ad93-408f-a226-647a0b05084e</td>\n",
       "      <td>徐旖芊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1512ca67-8e1d-4c95-877d-0e021cf12baf</td>\n",
       "      <td>刘心如</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>d902078a-133b-489b-b89b-79ee0322debb</td>\n",
       "      <td>刘宇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0bf2587d-1859-4538-b213-a7b6834b3545</td>\n",
       "      <td>李婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>89f838e1-f31c-4139-a0f4-9143a80b435d</td>\n",
       "      <td>黄智毅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>930bf6f4-0e19-498e-b762-201a52a4c8e7</td>\n",
       "      <td>黄慧文</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>80f63719-e49b-4339-86c3-39174f722285</td>\n",
       "      <td>张铭睿</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>dadcbc6b-a994-424b-aa51-b33eda6f0ac8</td>\n",
       "      <td>陈婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>aa22e7e8-6982-461c-bb1b-078d1a749788</td>\n",
       "      <td>洪可凡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>5d14f8be-2ef9-43b2-a6ad-de0ddb3a5314</td>\n",
       "      <td>卢继志</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>6ea2f3a0-f320-429b-a925-f20f51fbc1a2</td>\n",
       "      <td>张梓乐</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId userData\n",
       "0   1374fada-26f6-4ba6-bc94-a9e794a51de5      李振宁\n",
       "1   9923a82f-54ae-4fa0-93ff-a8632e156110      丘天惠\n",
       "2   c0faac8e-cb3f-48c7-81ce-e5e8f0121e08      林嘉茵\n",
       "3   b7a8d8c5-50a9-4b00-b8c2-935190d5fb16      汤玲萍\n",
       "4   1a63b72b-15be-421c-bddd-23e0aeada20a      曾雯燕\n",
       "5   2ccf8811-ec00-493f-9fb0-c6d18928a641      谢依希\n",
       "6   d78b42f7-1cbc-437e-ae90-71d5c827e56d      杨悦聪\n",
       "7   847f3691-2cc8-4c63-9673-815105277146       周雨\n",
       "8   d81c998a-0bfc-4fd8-bd00-2c06e50902e7      刘瑜鹏\n",
       "9   2dada7df-3292-4001-aeb6-4c8448be98eb      陈嘉仪\n",
       "10  c64170ef-ad93-408f-a226-647a0b05084e      徐旖芊\n",
       "11  1512ca67-8e1d-4c95-877d-0e021cf12baf      刘心如\n",
       "12  d902078a-133b-489b-b89b-79ee0322debb       刘宇\n",
       "13  0bf2587d-1859-4538-b213-a7b6834b3545       李婷\n",
       "14  89f838e1-f31c-4139-a0f4-9143a80b435d      黄智毅\n",
       "15  930bf6f4-0e19-498e-b762-201a52a4c8e7      黄慧文\n",
       "16  80f63719-e49b-4339-86c3-39174f722285      张铭睿\n",
       "17  dadcbc6b-a994-424b-aa51-b33eda6f0ac8       陈婷\n",
       "18  aa22e7e8-6982-461c-bb1b-078d1a749788      洪可凡\n",
       "19  5d14f8be-2ef9-43b2-a6ad-de0ddb3a5314      卢继志\n",
       "20  6ea2f3a0-f320-429b-a925-f20f51fbc1a2      张梓乐"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用Pandas简化数据\n",
    "import pandas as pd\n",
    "# 返回facelist数据\n",
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374fada-26f6-4ba6-bc94-a9e794a51de5</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>c64170ef-ad93-408f-a226-647a0b05084e</td>\n",
       "      <td>0.37464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>80f63719-e49b-4339-86c3-39174f722285</td>\n",
       "      <td>0.37120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0bf2587d-1859-4538-b213-a7b6834b3545</td>\n",
       "      <td>0.36362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1a63b72b-15be-421c-bddd-23e0aeada20a</td>\n",
       "      <td>0.33239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>b7a8d8c5-50a9-4b00-b8c2-935190d5fb16</td>\n",
       "      <td>0.26854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>c0faac8e-cb3f-48c7-81ce-e5e8f0121e08</td>\n",
       "      <td>0.26598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>6ea2f3a0-f320-429b-a925-f20f51fbc1a2</td>\n",
       "      <td>0.24914</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>aa22e7e8-6982-461c-bb1b-078d1a749788</td>\n",
       "      <td>0.20007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2dada7df-3292-4001-aeb6-4c8448be98eb</td>\n",
       "      <td>0.16117</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  1374fada-26f6-4ba6-bc94-a9e794a51de5     1.00000\n",
       "1  c64170ef-ad93-408f-a226-647a0b05084e     0.37464\n",
       "2  80f63719-e49b-4339-86c3-39174f722285     0.37120\n",
       "3  0bf2587d-1859-4538-b213-a7b6834b3545     0.36362\n",
       "4  1a63b72b-15be-421c-bddd-23e0aeada20a     0.33239\n",
       "5  b7a8d8c5-50a9-4b00-b8c2-935190d5fb16     0.26854\n",
       "6  c0faac8e-cb3f-48c7-81ce-e5e8f0121e08     0.26598\n",
       "7  6ea2f3a0-f320-429b-a925-f20f51fbc1a2     0.24914\n",
       "8  aa22e7e8-6982-461c-bb1b-078d1a749788     0.20007\n",
       "9  2dada7df-3292-4001-aeb6-4c8448be98eb     0.16117"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度数据\n",
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374fada-26f6-4ba6-bc94-a9e794a51de5</td>\n",
       "      <td>李振宁</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>c64170ef-ad93-408f-a226-647a0b05084e</td>\n",
       "      <td>徐旖芊</td>\n",
       "      <td>0.37464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>80f63719-e49b-4339-86c3-39174f722285</td>\n",
       "      <td>张铭睿</td>\n",
       "      <td>0.37120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0bf2587d-1859-4538-b213-a7b6834b3545</td>\n",
       "      <td>李婷</td>\n",
       "      <td>0.36362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1a63b72b-15be-421c-bddd-23e0aeada20a</td>\n",
       "      <td>曾雯燕</td>\n",
       "      <td>0.33239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b7a8d8c5-50a9-4b00-b8c2-935190d5fb16</td>\n",
       "      <td>汤玲萍</td>\n",
       "      <td>0.26854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>c0faac8e-cb3f-48c7-81ce-e5e8f0121e08</td>\n",
       "      <td>林嘉茵</td>\n",
       "      <td>0.26598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>6ea2f3a0-f320-429b-a925-f20f51fbc1a2</td>\n",
       "      <td>张梓乐</td>\n",
       "      <td>0.24914</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>aa22e7e8-6982-461c-bb1b-078d1a749788</td>\n",
       "      <td>洪可凡</td>\n",
       "      <td>0.20007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2dada7df-3292-4001-aeb6-4c8448be98eb</td>\n",
       "      <td>陈嘉仪</td>\n",
       "      <td>0.16117</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData  confidence\n",
       "0  1374fada-26f6-4ba6-bc94-a9e794a51de5      李振宁     1.00000\n",
       "5  c64170ef-ad93-408f-a226-647a0b05084e      徐旖芊     0.37464\n",
       "7  80f63719-e49b-4339-86c3-39174f722285      张铭睿     0.37120\n",
       "6  0bf2587d-1859-4538-b213-a7b6834b3545       李婷     0.36362\n",
       "3  1a63b72b-15be-421c-bddd-23e0aeada20a      曾雯燕     0.33239\n",
       "2  b7a8d8c5-50a9-4b00-b8c2-935190d5fb16      汤玲萍     0.26854\n",
       "1  c0faac8e-cb3f-48c7-81ce-e5e8f0121e08      林嘉茵     0.26598\n",
       "9  6ea2f3a0-f320-429b-a925-f20f51fbc1a2      张梓乐     0.24914\n",
       "8  aa22e7e8-6982-461c-bb1b-078d1a749788      洪可凡     0.20007\n",
       "4  2dada7df-3292-4001-aeb6-4c8448be98eb      陈嘉仪     0.16117"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并\n",
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 5.删除人脸/人脸列表\n",
    "faceListId = \"list_007\" # 需要删除的人脸列表\n",
    "# 删除列表内人脸\n",
    "delete_face_url = \"https://api-jun.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedfaces/{}\"\n",
    "assert subscription_key\n",
    "# 获取上面的persistedFaceId\n",
    "persistedFaceId = r_add_face.json()[\"persistedFaceId\"] \n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "# 注意requests请求为delete\n",
    "r_delete_face = requests.delete(delete_face_url.format(faceListId,persistedFaceId),headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除人脸列表\n",
    "delete_facelist_url = \"https://api-jun.cognitiveservices.azure.com/face/v1.0/facelists/{}\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "r_delete_facelist = requests.delete(delete_facelist_url.format(faceListId),headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_face"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_facelist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.Face++"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1  `Face detect`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1、先导入为们需要的模块\n",
    "import requests\n",
    "\n",
    "api_secret = \"qLuVbjFMmRdz7zodWrEpC1jJXiMnVBTi\"\n",
    "# 2、输入我们API_Key\n",
    "api_key = '_K58BjIyIDt-ksqx-MGPfzqiPwwbQy6k'  # Replace with a valid Subscription Key here.\n",
    "\n",
    "\n",
    "# 3、目标url\n",
    "\n",
    "# 这里也可以使用本地图片 例如：filepath =\"image/tupian.jpg\"\n",
    "BASE_URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect' \n",
    "img_url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603446871485&di=ea65241de93bde5ff5f6e0b12b3557f8&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F01%2F20191201160513_imlxt.thumb.400_0.jpg'\n",
    "\n",
    "# 4、沿用API文档的示范代码,准备我们的headers和图片(数据)\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "\n",
    "# 5、准备symbol ? 后面的数据\n",
    "payload = {\n",
    "    \"image_url\":img_url,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,smiling,emotion', \n",
    "}\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  6、requests发送我们请求\n",
    "r = requests.post(BASE_URL, params=payload, headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1603514234,d1888fb0-1db3-4198-bb5d-f007093d0e57\",\"time_used\":202,\"faces\":[{\"face_token\":\"2aae2d7e2855b31f01f712b6d40a3563\",\"face_rectangle\":{\"top\":103,\"left\":155,\"width\":112,\"height\":112},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":26},\"smile\":{\"value\":97.003,\"threshold\":50.000},\"emotion\":{\"anger\":0.030,\"disgust\":1.284,\"fear\":0.008,\"happiness\":96.270,\"neutral\":2.393,\"sadness\":0.008,\"surprise\":0.008}}}],\"image_id\":\"3n++W8yLmLy2E6vHJTAmhA==\",\"face_num\":1}\\n'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1603514234,d1888fb0-1db3-4198-bb5d-f007093d0e57',\n",
       " 'time_used': 202,\n",
       " 'faces': [{'face_token': '2aae2d7e2855b31f01f712b6d40a3563',\n",
       "   'face_rectangle': {'top': 103, 'left': 155, 'width': 112, 'height': 112},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 26},\n",
       "    'smile': {'value': 97.003, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.03,\n",
       "     'disgust': 1.284,\n",
       "     'fear': 0.008,\n",
       "     'happiness': 96.27,\n",
       "     'neutral': 2.393,\n",
       "     'sadness': 0.008,\n",
       "     'surprise': 0.008}}}],\n",
       " 'image_id': '3n++W8yLmLy2E6vHJTAmhA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# requests 巧妙的方法   r = response\n",
    "results = r.json() # \n",
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2  `Face list & Face similar`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3213bd6a03f887dbc2263499a9ba78fc',\n",
       " 'time_used': 148,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603514769,09961d62-9be9-485d-abe7-8e989f4c9f4a',\n",
       " 'outer_id': '20190071',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "api_secret = \"qLuVbjFMmRdz7zodWrEpC1jJXiMnVBTi\"\n",
    "api_key = \"_K58BjIyIDt-ksqx-MGPfzqiPwwbQy6k\"\n",
    "\n",
    "# 1.FaceSet Create\n",
    "import requests,json\n",
    "\n",
    "display_name = \"人脸集合\" #自定义人脸集合的名字\n",
    "outer_id = \"20190071\" #自定义标识\n",
    "user_data = \"test\" #自定义用户信息\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\" #调用URL\n",
    "payload = {\n",
    "    # 请求参数\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n",
    "r = requests.post(CreateFace_Url, params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3213bd6a03f887dbc2263499a9ba78fc',\n",
       " 'tags': '',\n",
       " 'time_used': 108,\n",
       " 'user_data': 'test',\n",
       " 'display_name': '人脸集合',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603514772,daab7705-7f2a-4be9-8ba9-ed52368aa821',\n",
       " 'outer_id': '20190071'}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.FaceSet GetDetail（获取人脸集合信息）\n",
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'outer_id':outer_id,\n",
    "}\n",
    "r = requests.post(GetDetail_Url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'bd7c682c0ce58d9b1be3d84e7f6fbdff',\n",
       " 'time_used': 484,\n",
       " 'face_count': 1,\n",
       " 'face_added': 1,\n",
       " 'request_id': '1603514776,e83cd012-e0f3-4f3d-902f-923964578ea2',\n",
       " 'outer_id': '201971',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.FaceSet AddFace（增加人脸信息）\n",
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'bd7c682c0ce58d9b1be3d84e7f6fbdff',\n",
    "    'face_tokens':'b0e03de4bb46391920f3ddb55fc66451', # detect里获取的\n",
    "}\n",
    "r = requests.post(AddFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'bd7c682c0ce58d9b1be3d84e7f6fbdff',\n",
       " 'face_removed': 1,\n",
       " 'time_used': 198,\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603514779,4d8400a6-1a4a-4ec8-b0b8-07786463745f',\n",
       " 'outer_id': '201971',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.FaceSet RemoveFace（移除人脸信息）\n",
    "RemoveFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'bd7c682c0ce58d9b1be3d84e7f6fbdff',\n",
    "    'face_tokens':'b0e03de4bb46391920f3ddb55fc66451',\n",
    "}\n",
    "r = requests.post(RemoveFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'bd7c682c0ce58d9b1be3d84e7f6fbdff',\n",
       " 'request_id': '1603514782,ff71f2f3-74cf-4e53-b2c3-638fb542513d',\n",
       " 'time_used': 68,\n",
       " 'outer_id': '201971'}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.FaceSet Update（更新人脸集合信息）\n",
    "Update_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/update\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'bd7c682c0ce58d9b1be3d84e7f6fbdff',\n",
    "    'user_data':\"Test.\",\n",
    "}\n",
    "r = requests.post(Update_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faces1': [{'face_rectangle': {'width': 318,\n",
       "    'top': 222,\n",
       "    'left': 511,\n",
       "    'height': 318},\n",
       "   'face_token': '0594a5d93cba56f4dcf30de8054f4010'}],\n",
       " 'faces2': [{'face_rectangle': {'width': 112,\n",
       "    'top': 103,\n",
       "    'left': 155,\n",
       "    'height': 112},\n",
       "   'face_token': '942d1c08fcf474993729070cefe8bd3d'}],\n",
       " 'time_used': 1498,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'confidence': 66.794,\n",
       " 'image_id2': '3n++W8yLmLy2E6vHJTAmhA==',\n",
       " 'image_id1': '7tCG+09f2ye5Slj8ep+zEA==',\n",
       " 'request_id': '1603514790,6814149f-9e69-44c6-b429-5a8725c7187f'}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6.Compare Face（对比人脸相似度）\n",
    "baijingting = \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603473409854&di=14c4aab8feb54fb9573ef81150958a42&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201802%2F28%2F20180228081644_vjXZ8.jpeg\"\n",
    "lizhenning = \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603473535219&di=6f391139fac888b4c9da71c577cc9196&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F01%2F20191201160513_imlxt.thumb.400_0.jpg\"\n",
    "\n",
    "\n",
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "payload ={\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url1':baijingting,\n",
    "    'image_url2':lizhenning\n",
    "}\n",
    "r = requests.post(Compare_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 百度智能云"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1  `Face detect` "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'refresh_token': '25.41f713dad3d73c9d3407da2baeeb3db4.315360000.1918875563.282335-22867684',\n",
       " 'expires_in': 2592000,\n",
       " 'session_key': '9mzdCyjIrM6YdkeXSkEPXcnKNw7R+r8545LkiViJX+ekzWrU3zrR76JVNX5HjEZZqiSboVODM1Ju5JMYP7yywhkC8PIclQ==',\n",
       " 'access_token': '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684',\n",
       " 'scope': 'public brain_all_scope vis-faceverify_faceverify_h5-face-liveness vis-faceverify_FACE_V3 vis-faceverify_idl_face_merge vis-faceverify_FACE_EFFECT vis-faceverify_face_feature_sdk wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component',\n",
       " 'session_secret': '42e80494cf0ef7381cee8ea4b0e36d1b'}"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={}&client_secret={}'\n",
    "client_id = \"GEsCzg308uzDh73oCIplDtmt\"\n",
    "client_secret = \"Prjarknh9Li8lFGvxaoznjgGr0CaacXq\"\n",
    "response = requests.get(host.format(client_id, client_secret))\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 0,\n",
       " 'error_msg': 'SUCCESS',\n",
       " 'log_id': 19905201458,\n",
       " 'timestamp': 1603517831,\n",
       " 'cached': 0,\n",
       " 'result': {'face_num': 1,\n",
       "  'face_list': [{'face_token': '2efaa6af5408c4c012fe5896cb973777',\n",
       "    'location': {'left': 137.32,\n",
       "     'top': 206.1,\n",
       "     'width': 218,\n",
       "     'height': 201,\n",
       "     'rotation': -9},\n",
       "    'face_probability': 1,\n",
       "    'angle': {'yaw': 10.98, 'pitch': 20.93, 'roll': -16.32},\n",
       "    'face_shape': {'type': 'oval', 'probability': 0.49},\n",
       "    'face_type': {'type': 'human', 'probability': 0.63}}]}}"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.人脸检测与属性分析\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/detect\"\n",
    "\n",
    "params = \"{\\\"image\\\":\\\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603477338664&di=ab781cd4f020408f82c202eca1d98a2d&imgtype=0&src=http%3A%2F%2Fi2.hdslb.com%2Fbfs%2Fface%2Fcf74e3985c240caa92b33198e1dbe22caae92eb1.jpg\\\",\\\"image_type\\\":\\\"URL\\\",\\\"face_field\\\":\\\"faceshape,facetype\\\"}\"\n",
    "# image_type 图片类型：BASE64；URL；FACE_TOKEN。\n",
    "\n",
    "access_token = '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 0,\n",
       " 'error_msg': 'SUCCESS',\n",
       " 'log_id': 7915797555351,\n",
       " 'timestamp': 1603517847,\n",
       " 'cached': 0,\n",
       " 'result': {'score': 7.499267578,\n",
       "  'face_list': [{'face_token': '2efaa6af5408c4c012fe5896cb973777'},\n",
       "   {'face_token': '93d2501e1cb1685c26107d0b19cc854a'}]}}"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.人脸对比\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/match\"\n",
    "\n",
    "params = \"[{\\\"image\\\": \\\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603477338664&di=ab781cd4f020408f82c202eca1d98a2d&imgtype=0&src=http%3A%2F%2Fi2.hdslb.com%2Fbfs%2Fface%2Fcf74e3985c240caa92b33198e1dbe22caae92eb1.jpg\\\", \\\"image_type\\\": \\\"URL\\\", \\\"face_type\\\": \\\"CERT\\\", \\\"quality_control\\\": \\\"LOW\\\"}, {\\\"image\\\": \\\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603015508446&di=eee4e2c852d804bc3b80a719df3df9ef&imgtype=0&src=http%3A%2F%2Fimg2-cloud.itouchtv.cn%2Ftvtouchtv%2Fimage%2F20170914%2F1505363583630378.jpg\\\", \\\"image_type\\\": \\\"URL\\\", \\\"face_type\\\": \\\"LIVE\\\", \\\"quality_control\\\": \\\"LOW\\\"}]\"\n",
    "# face_type 人脸的类型 LIVE；IDCARD；WATERMARK；CERT；INFRARED。\n",
    "\n",
    "access_token = '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2  `Face comparison` "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 223101,\n",
       " 'error_msg': 'group already exist',\n",
       " 'log_id': 2510145840013,\n",
       " 'timestamp': 1603517874,\n",
       " 'cached': 0,\n",
       " 'result': None}"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.创建用户组\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/add\"\n",
    "\n",
    "params = \"{\\\"group_id\\\":\\\"group2\\\"}\"\n",
    "access_token = '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 223120,\n",
       " 'error_msg': 'liveness check fail',\n",
       " 'log_id': 579158975059,\n",
       " 'timestamp': 1603517897,\n",
       " 'cached': 0,\n",
       " 'result': None}"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.人脸注册\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add\"\n",
    "\n",
    "params = \"{\\\"image\\\":\\\"2efaa6af5408c4c012fe5896cb973777\\\",\\\"image_type\\\":\\\"FACE_TOKEN\\\",\\\"group_id\\\":\\\"group2\\\",\\\"user_id\\\":\\\"user1\\\",\\\"user_info\\\":\\\"abc\\\",\\\"quality_control\\\":\\\"LOW\\\",\\\"liveness_control\\\":\\\"NORMAL\\\"}\"\n",
    "access_token = '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 223103,\n",
       " 'error_msg': 'user not exist',\n",
       " 'log_id': 9975992017994,\n",
       " 'timestamp': 1603517927,\n",
       " 'cached': 0,\n",
       " 'result': None}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.获取用户人脸列表\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/getlist\"\n",
    "\n",
    "params = \"{\\\"user_id\\\":\\\"user1\\\",\\\"group_id\\\":\\\"group2\\\"}\"\n",
    "access_token = '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 223100,\n",
       " 'error_msg': 'group not exist',\n",
       " 'log_id': 8435001758979,\n",
       " 'timestamp': 1603517947,\n",
       " 'cached': 0,\n",
       " 'result': None}"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6.删除用户组\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/delete\"\n",
    "\n",
    "params = \"{\\\"group_id\\\":\\\"group1\\\"}\"\n",
    "access_token = '24.009c263ec7e1edad7198013e35de63eb.2592000.1606107563.282335-22867684' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
